package com.reflex;

import java.lang.reflect.Field;

public class ReflexDemo08 {
    public static void main(String[] args) throws Exception {
        // 获取Class对象
        Class<?> aClass = Class.forName("com.reflex.Teacher");
        // 创建对象
        Object object = aClass.newInstance();
        // 获取属性
        Field field1 = aClass.getField("name");
        field1.set(object,"张三");

        Field field2 = aClass.getField("age");
        field2.set(object,18);
        System.out.println(object);

        //
        Object object1 = field1.get(object);
        Object object2 = field2.get(object);
        System.out.println("object1 = " + object1);
        System.out.println("object2 = " + object2);

    }
}
